package com.dstz.bpm.engine.plugin.factory;

import cn.hutool.core.collection.CollectionUtil;
import com.dstz.base.core.util.AppUtil;
import com.dstz.bpm.api.constant.EventType;
import com.dstz.bpm.api.engine.plugin.context.BpmPluginContext;
import com.dstz.bpm.engine.plugin.runtime.BpmExecutionPlugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BpmPluginFactory {
   protected static Logger LOG = LoggerFactory.getLogger(BpmPluginFactory.class);

   public static BpmExecutionPlugin buildExecutionPlugin(BpmPluginContext bpmPluginContext, EventType eventType) {
      if (CollectionUtil.isEmpty(bpmPluginContext.getEventTypes())) {
         return null;
      } else {
         if (bpmPluginContext.getEventTypes().contains(eventType)) {
            try {
               BpmExecutionPlugin bpmExecutionPlugin = (BpmExecutionPlugin)AppUtil.getBean(bpmPluginContext.getPluginClass());
               return bpmExecutionPlugin;
            } catch (Exception var3) {
               var3.printStackTrace();
            }
         } else {
            LOG.trace("插件【{}】未注册[{}]事件，跳过执行！ 插件时机：{}", new Object[]{bpmPluginContext.getTitle(), eventType, bpmPluginContext.getEventTypes()});
         }

         return null;
      }
   }
}
